<?php
/**
 * Created by PhpStorm.
 * User: DELL
 * Date: 2018/4/22
 * Time: 21:32
 */

namespace app\home\controller;
use app\home\model\WechatUser;
use com\wechat\TPWechat;
use think\Config;
use think\Controller;
use app\admin\model\Sign;
use app\home\model\Summary;
class Call extends Controller
{
    /**
     * 签到 提醒
     */
    public function one(){
        // 周一 不进行推送
        if (date("N", time()) != 1) {  
            $Users = WechatUser::where(['subscribe' => 1, 'review_status' => 1,'role' => 0])->column('openid');
            $Wechat = new TPWechat(Config::get('party'));
            $con = '【温馨提示】
同学，今日签到完成了吗？不要忘记签到哦~~，业精于勤，荒于嬉；行成于思，毁于随。加油！！！';
            $send = array(
                "content" => $con
            );
            foreach ($Users as $value){
                $res = Sign::where(['openid' => $value])->whereTime('create_time','d')->find();
                if (empty($res)){
                    $data = array(
                        "touser" => $value,
                        "msgtype" => "text",
                        "text" => $send
                    );
                    $Wechat->sendCustomMessage($data);
                }
            }
        }
    }
    /**
     * 总结提醒
     */
    public function two(){
        // 周一 不进行推送
        if (date("N", time()) != 1) {
            $Users = WechatUser::where(['subscribe' => 1, 'review_status' => 1,'role' => 0])->column('openid');
            $Wechat = new TPWechat(Config::get('party'));
            $con = '【温馨提示】
同学，今日总结完成了吗？不要忘记提交哦~~，点击_<a href="http://mp.csppat.com/DDDeducation/public/index.php/home/Journal/publishs">总结提交</a>_可快速编写，将来的你一定会感谢现在奋斗的自己。加油！！！';
            $send = array(
                "content" => $con
            );
            foreach ($Users as $value){
                $res = Summary::where(['openid' => $value,'status' => 0])->whereTime('create_time','d')->find();
                if (empty($res)){
                    $data = array(
                        "touser" => $value,
                        "msgtype" => "text",
                        "text" => $send
                    );
                    $Wechat->sendCustomMessage($data);
                }
            }
        }
    }
}